import Request from "@/common/utils/request/index";
import { CreatePurchaseOrderDto } from "@/types/model/purchase/dtos/purchase.dto";
import { AddTradeInNoteDTO } from "@/types/model/purchase/dtos/tradeinOrder.dto";
import { PurchaseNote } from "@/types/model/purchase/vos/tradeinOrder.vo";

enum Api {
  GetPurchaseOrderList = "/jeecgboot/posPurchase/list",
  AddTradeInPayment = "/jeecgboot/posPurchasePayments/addTradeInPayment",
  GetNotesByPurchaseId = "/jeecgboot/posPurchaseNote/getNotesByPurchaseId",
  CreateTradeInNote = "/jeecgboot/posPurchaseNote/addTradeInNote",
  CreatePurchaseOrder = "/jeecgboot/posPurchase/createPurchaseOrder",
  ChangePurchaseOrderStatus = "/jeecgboot/posPurchase/changeOrderStatus",
  GetPurchaseOrderDetail = "/jeecgboot/posPurchase/getOrderDetail",
  CompleteOrder = "/jeecgboot/posPurchase/completeOrder"
}

export const getPurchaseOrderList = (params: any) => {
  return Request.getInstance().send({
    url: Api.GetPurchaseOrderList,
    method: "GET",
    params,
  });
};

export const addTradeInPayment = (params: any) => {
  return Request.getInstance().send({
    url: Api.AddTradeInPayment,
    method: "POST",
    data: params,
  });
};

export const getNotesByPurchaseId = (purchaseId: string) => {
  return Request.getInstance().send<PurchaseNote[]>({
    url: Api.GetNotesByPurchaseId,
    method: "GET",
    params: {
      purchaseId,
    },
  });
};

export const createTradeInNote = (params: AddTradeInNoteDTO) => {
  return Request.getInstance().send({
    url: Api.CreateTradeInNote,
    method: "POST",
    data: params,
  });
};

export const createPurchaseOrder = (params: CreatePurchaseOrderDto) => {
  return Request.getInstance().send({
    url: Api.CreatePurchaseOrder,
    method: "POST",
    data: params,
  });
};

export const changePurchaseOrderStatus = (params: {
  orderId: string;
  status: string;
  bizType: String;
}) => {
  return Request.getInstance().send({
    url: Api.ChangePurchaseOrderStatus,
    method: "POST",
    data: params,
  });
};

export const getPurchaseOrderDetail = (orderId: string) => {
  return Request.getInstance().send({
    url: Api.GetPurchaseOrderDetail,
    method: "GET",
    params: {
      id: orderId,
    },
  });
};

export const completeOrder = (orderId: string) => {
  return Request.getInstance().send({
    url: Api.CompleteOrder,
    method: "POST",
    data: {
      orderId,
    },
  });
};